package com.cl.utility.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cl.utility.annocation.NoAuthorization;
import com.cl.utility.constant.Message;
import com.cl.utility.pojo.ResultCode;
import com.cl.utility.pojo.Student;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author liddhappy
 * @description 测试
 * @date 2022/11/10 21:57
 */
@RestController
@RequestMapping("/demo")
public class DemoController {
    @GetMapping("/success")
    public ResultCode<JSONObject> demoSuccess() {
        JSONObject jsonObject = new JSONObject();
        Student student = new Student();
        student.setName("liddhappy");
        student.setAge(22);
        student.setSex("male");
        student.setAddress("ocg");
        jsonObject.put("student", student);
        return new ResultCode<>(Message.Success(), jsonObject);
    }

    @GetMapping("/failed")
    public ResultCode<String> demoFailed() {
        return new ResultCode<>(Message.Failed(), "not data");
    }

    @PostMapping("/warn")
    public ResultCode<JSONObject> demoWarn(Student student) {
        JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(student));
        return new ResultCode<>(Message.WARN("student object don't not empty name"), jsonObject);
    }

    @PostMapping("/error")
    public ResultCode<JSONObject> demoError(Student student) {

        JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(student));
        return new ResultCode<>(Message.ERROR("it's not empty student object"), jsonObject);
    }
}
